import request from '@/utils/request.ts'
import { roleResponseData, roleData } from './type.ts'
// 获取角色
export const getRoleList = (
  page: number,
  limit: number,
  roleName: string | number,
) =>
  request.get<any, roleResponseData>(
    `/admin/acl/role/${page}/${limit}?roleName=${roleName}`,
  )
// 添加或修改角色
export const addOrUpdateRole = (data: roleData) => {
  if (data.id) {
    return request.put<any, any>(`/admin/acl/role/update`, data)
  } else {
    return request.post<any, any>(`/admin/acl/role/save`, data)
  }
}
// 删除角色
export const removeRole = (id: number | string) =>
  request.delete(`/admin/acl/role/remove/${id}`)
// 获取全部菜单与按钮权限
export const getAllMenu = (roleId: number) =>
  request.get(`/admin/acl/permission/toAssign/${roleId}`)
// 根据角色获取权限
export const getAclByRole = (roleId: number, permissionId: number[]) =>
  request.post(
    `/admin/acl/permission/doAssign?roleId=${roleId}&permissionId=${permissionId}`,
  )
